# 自动化操作账户系统的API接口

import requests
import json

import config

# 登录接口
def login(username, password):
    send_data = {
        "username": username,
        "password": password
    }
    response = requests.post(config.user_server + "/login", data=json.dumps(send_data))
    return response.text

# 注册接口
def register(username, password, email,captcha):
    send_data = {
        "username": username,
        "password": password,
        "email": email,
        "captcha": captcha
    }
    response = requests.post(config.user_server + "/register", data=json.dumps(send_data))
    return response.text

# 获取邮箱验证码接口
def get_email_captcha(email):
    send_data = {
        "to": email
    }
    response = requests.post(config.user_server + "/get_captcha", data=json.dumps(send_data))
    return response.text

# 获取用户信息接口
def get_user_info(token):
    send_data = {
        "session_code" : token
    }
    response = requests.post(config.user_server + "/get_user_info", data=json.dumps(send_data))
    return response.text

# 获取图片验证码接口
def get_image_captcha():
    response = requests.get(config.user_server + "/get_anti_captcha")
    return response.content

# 退出登录接口
def logout(token):
    send_data = {
        "session_code" : token
    }
    response = requests.post(config.user_server + "/logout", data=json.dumps(send_data))
    return response.text

# 邮箱验证码登录
def email_login(email, captcha):
    send_data = {
        "email": email,
        "captcha": captcha
    }
    response = requests.post(config.user_server + "/email_login", data=json.dumps(send_data))
    return response.text